package com.tim.app.ui.adapter.personal;

import android.util.ArrayMap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.application.library.util.TimeUtil;
import com.application.library.widget.recycle.BaseRecyclerAdapter;
import com.tim.app.R;
import com.tim.app.server.result.IncomeDetailBean;
import com.tim.app.util.AppDate;

import java.util.List;

/**
 * Created by wdy on 2017/8/22.
 */

public class IncomeFlowerDetailAdapter extends BaseRecyclerAdapter<IncomeFlowerDetailAdapter.ViewHolder, IncomeDetailBean.ResBean.ArraylistBean.ResultBean> {

    public IncomeFlowerDetailAdapter(List<IncomeDetailBean.ResBean.ArraylistBean.ResultBean> result) {
        super(result);
    }

    @Override
    public IncomeFlowerDetailAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder holder = new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_income_detail, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(IncomeFlowerDetailAdapter.ViewHolder holder, int position, IncomeDetailBean.ResBean.ArraylistBean.ResultBean data) {
        if ("reduce".equals(data.getDataType())) {
            holder.tv_income_num.setText("-" + (int) data.getChangeCount() + "朵");
        } else {
            holder.tv_income_num.setText("+" + (int) data.getChangeCount() + "朵");
        }
        String s = AppDate.flower.get(data.getOperationType()) == null ? data.getOperationType() : AppDate.flower.get(data.getOperationType());
        holder.tv_income_type.setText(s);
        holder.tv_income_time.setText(TimeUtil.dateToDate(data.getCreateTime() + ""));
    }

    public static class ViewHolder extends BaseRecyclerAdapter.BaseRecyclerViewHolder {
        TextView tv_income_type, tv_income_num, tv_income_time;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_income_type = (TextView) itemView.findViewById(R.id.tv_income_type);
            tv_income_num = (TextView) itemView.findViewById(R.id.tv_income_num);
            tv_income_time = (TextView) itemView.findViewById(R.id.tv_income_time);
        }
    }
}
